


import Common from './common';

export default class ButtonAction extends Common {
    constructor(comp) {
        super();
        this.comp = comp;
    }

    // 主页面卡片点击回调
    analysisAreaHandle = (type) => {

        return () => {
            const {
                props: {
                    dispatch,
                    sca
                }
            } = this.comp;

            this.update({
                page: type,
                exportValue: null,
                pageInfo: {
                    pageIndex: 1,
                    pageSize: 10,
                    total: 0,
                    totalPage: 1
                },
            });

            if(sca.orgValue[type]) {
                this.pubSub.publish('getMainTable', {
                    type: type
                });
            }
        }

    }

    // 头部按钮点击回调
    headerClick = (props, btnCode) => {
        const {
            props: {
                sca,
                search
            }
        } = this.comp;

        if(btnCode === 'query') {
            let searchId = this.searchMap[sca.page];
            search.openAdvSearch(searchId, true);
        }
        else if(btnCode === 'export') {
            this.pubSub.publish('showExportModal');
        }
    }

    // 返回主页面
    goBackToMain = () => {
        this.comp.props.dispatch({
            type: 'sca/handleParamsByKey',
            payload: {
                page: 'main',
                pageInfo: {
                    pageIndex: 1,
                    pageSize: 10,
                    total: 0,
                    totalPage: 1
                }
            }
        });
    }

    // 组织参照修改
    changeOrg = (value) => {
        const {
            props: {
                sca,
                dispatch
            }
        } = this.comp;
        if(Object.keys(value).length <= 0) {
            value = null;
        }
        dispatch({
            type: 'sca/handleParamsByKey',
            payload: {
                orgValue: {
                    [sca.page]: value
                }
            }
        });

        // this.pubSub.publish('getMainTable', {
        //     pk_org: value ? value.refpk : ''
        // });
    }
}